package com.navinfo.tripanalysis.common.arithmetic;

import com.navinfo.tripanalysis.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.tripanalysis.common.util.ArithmeticUtils;
import com.navinfo.tripanalysis.common.arithmetic.common.CommonData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticData;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarRangeRotation;
import com.navinfo.tripanalysis.common.arithmetic.common.VarCommon;
import com.navinfo.tripanalysis.common.arithmetic.enums.RangeRpmEnum;

/**
 * 发动机转速区间统计算法<br/>
 * 依赖{@link IdleParking}怠速算法<br/>
 * 依赖{@link Mileage}里程油耗算法<br/>
 * 输出：统计
 * @author web
 */
public class RangeRotation extends AbstractArithmetic<VarRangeRotation> {

    @Override
    public void calculate() {
        logger.debug("进入发动机转速区间统计算法.");
        VarRangeRotation var = getObj();
        CommonData commonData = getCommonData();

        int rotation = commonData.getRotation();

        //转数有效性校验
        if (!RangeRpmEnum.RANGE_OVER_VALID.getRange().contains(rotation)) {
            return;
        }

        //获取相应转速区间的公共统计变量
        VarCommon rpmVar = null;
        if (RangeRpmEnum.RANGE_500.getRange().contains(rotation)) {
            rpmVar = var.getRpm500();
        }else if (RangeRpmEnum.RANGE_600.getRange().contains(rotation)) {
            rpmVar = var.getRpm600();
        }else if (RangeRpmEnum.RANGE_700.getRange().contains(rotation)) {
            rpmVar = var.getRpm700();
        }else if (RangeRpmEnum.RANGE_800.getRange().contains(rotation)) {
            rpmVar = var.getRpm800();
        }else if (RangeRpmEnum.RANGE_900.getRange().contains(rotation)) {
            rpmVar = var.getRpm900();
        }else if (RangeRpmEnum.RANGE_1000.getRange().contains(rotation)) {
            rpmVar = var.getRpm1000();
        }else if (RangeRpmEnum.RANGE_1100.getRange().contains(rotation)) {
            rpmVar = var.getRpm1100();
        }else if (RangeRpmEnum.RANGE_1200.getRange().contains(rotation)) {
            rpmVar = var.getRpm1200();
        }else if (RangeRpmEnum.RANGE_1300.getRange().contains(rotation)) {
            rpmVar = var.getRpm1300();
        }else if (RangeRpmEnum.RANGE_1400.getRange().contains(rotation)) {
            rpmVar = var.getRpm1400();
        }else if (RangeRpmEnum.RANGE_1500.getRange().contains(rotation)) {
            rpmVar = var.getRpm1500();
        }else if (RangeRpmEnum.RANGE_1600.getRange().contains(rotation)) {
            rpmVar = var.getRpm1600();
        }else if (RangeRpmEnum.RANGE_1700.getRange().contains(rotation)) {
            rpmVar = var.getRpm1700();
        }else if (RangeRpmEnum.RANGE_1800.getRange().contains(rotation)) {
            rpmVar = var.getRpm1800();
        }else if (RangeRpmEnum.RANGE_1900.getRange().contains(rotation)) {
            rpmVar = var.getRpm1900();
        }else if (RangeRpmEnum.RANGE_2000.getRange().contains(rotation)) {
            rpmVar = var.getRpm2000();
        }else if (RangeRpmEnum.RANGE_2100.getRange().contains(rotation)) {
            rpmVar = var.getRpm2100();
        }else if (RangeRpmEnum.RANGE_2200.getRange().contains(rotation)) {
            rpmVar = var.getRpm2200();
        }else if (RangeRpmEnum.RANGE_2300.getRange().contains(rotation)) {
            rpmVar = var.getRpm2300();
        }else if (RangeRpmEnum.RANGE_2400.getRange().contains(rotation)) {
            rpmVar = var.getRpm2400();
        }else if (RangeRpmEnum.RANGE_2500.getRange().contains(rotation)) {
            rpmVar = var.getRpm2500();
        }else if (RangeRpmEnum.RANGE_2600.getRange().contains(rotation)) {
            rpmVar = var.getRpm2600();
        }else if (RangeRpmEnum.RANGE_2700.getRange().contains(rotation)) {
            rpmVar = var.getRpm2700();
        }else if (RangeRpmEnum.RANGE_2800.getRange().contains(rotation)) {
            rpmVar = var.getRpm2800();
        }else if (RangeRpmEnum.RANGE_2900.getRange().contains(rotation)) {
            rpmVar = var.getRpm2900();
        }else if (RangeRpmEnum.RANGE_3000.getRange().contains(rotation)) {
            rpmVar = var.getRpm3000();
        }else if (RangeRpmEnum.RANGE_OVER_3000.getRange().contains(rotation)) {
            rpmVar = var.getRpmOver3000();
        }

        //累加相应转速区间的公共统计变量
        if(null != rpmVar){
            rpmVar.addMileage(commonData.getDffMileage());
            rpmVar.addFuel(commonData.getDffFuel());
            rpmVar.addDuration(commonData.getDffTime());
        }

        if (rotation > var.getMaxRpm()) {
            var.setMaxRpm(rotation);
        }
        if (rotation < var.getMinRpm()) {
            var.setMinRpm(rotation);
        }

        if (!commonData.isParkingIdle()) {
            var.setNoIdleRpmSum(var.getNoIdleRpmSum() + rotation);
            var.setNoIdleRpmCount(var.getNoIdleRpmCount() + 1);
        }

        var.setRpmSum(var.getRpmSum() + rotation);
        var.setRpmCount(var.getRpmCount() + 1);

        logger.debug("发动机转速区间统计算法结束.");
    }


    @Override
    public void collect(OuterStatisticData statisticData) {
        VarRangeRotation var = getObj();

        statisticData.setRpmRange500Mileage(ArithmeticUtils.mileageMToM(var.getRpm500().getMileage()));
        statisticData.setRpmRange500Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm500().getFuel()));
        statisticData.setRpmRange500Duration(ArithmeticUtils.timeMsToSecond(var.getRpm500().getDuration()));

        statisticData.setRpmRange600Mileage(ArithmeticUtils.mileageMToM(var.getRpm600().getMileage()));
        statisticData.setRpmRange600Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm600().getFuel()));
        statisticData.setRpmRange600Duration(ArithmeticUtils.timeMsToSecond(var.getRpm600().getDuration()));

        statisticData.setRpmRange700Mileage(ArithmeticUtils.mileageMToM(var.getRpm700().getMileage()));
        statisticData.setRpmRange700Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm700().getFuel()));
        statisticData.setRpmRange700Duration(ArithmeticUtils.timeMsToSecond(var.getRpm700().getDuration()));

        statisticData.setRpmRange800Mileage(ArithmeticUtils.mileageMToM(var.getRpm800().getMileage()));
        statisticData.setRpmRange800Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm800().getFuel()));
        statisticData.setRpmRange800Duration(ArithmeticUtils.timeMsToSecond(var.getRpm800().getDuration()));

        statisticData.setRpmRange900Mileage(ArithmeticUtils.mileageMToM(var.getRpm900().getMileage()));
        statisticData.setRpmRange900Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm900().getFuel()));
        statisticData.setRpmRange900Duration(ArithmeticUtils.timeMsToSecond(var.getRpm900().getDuration()));

        statisticData.setRpmRange1000Mileage(ArithmeticUtils.mileageMToM(var.getRpm1000().getMileage()));
        statisticData.setRpmRange1000Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1000().getFuel()));
        statisticData.setRpmRange1000Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1000().getDuration()));

        statisticData.setRpmRange1100Mileage(ArithmeticUtils.mileageMToM(var.getRpm1100().getMileage()));
        statisticData.setRpmRange1100Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1100().getFuel()));
        statisticData.setRpmRange1100Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1100().getDuration()));

        statisticData.setRpmRange1200Mileage(ArithmeticUtils.mileageMToM(var.getRpm1200().getMileage()));
        statisticData.setRpmRange1200Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1200().getFuel()));
        statisticData.setRpmRange1200Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1200().getDuration()));

        statisticData.setRpmRange1300Mileage(ArithmeticUtils.mileageMToM(var.getRpm1300().getMileage()));
        statisticData.setRpmRange1300Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1300().getFuel()));
        statisticData.setRpmRange1300Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1300().getDuration()));

        statisticData.setRpmRange1400Mileage(ArithmeticUtils.mileageMToM(var.getRpm1400().getMileage()));
        statisticData.setRpmRange1400Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1400().getFuel()));
        statisticData.setRpmRange1400Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1400().getDuration()));

        statisticData.setRpmRange1500Mileage(ArithmeticUtils.mileageMToM(var.getRpm1500().getMileage()));
        statisticData.setRpmRange1500Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1500().getFuel()));
        statisticData.setRpmRange1500Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1500().getDuration()));

        statisticData.setRpmRange1600Mileage(ArithmeticUtils.mileageMToM(var.getRpm1600().getMileage()));
        statisticData.setRpmRange1600Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1600().getFuel()));
        statisticData.setRpmRange1600Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1600().getDuration()));

        statisticData.setRpmRange1700Mileage(ArithmeticUtils.mileageMToM(var.getRpm1700().getMileage()));
        statisticData.setRpmRange1700Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1700().getFuel()));
        statisticData.setRpmRange1700Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1700().getDuration()));

        statisticData.setRpmRange1800Mileage(ArithmeticUtils.mileageMToM(var.getRpm1800().getMileage()));
        statisticData.setRpmRange1800Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1800().getFuel()));
        statisticData.setRpmRange1800Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1800().getDuration()));

        statisticData.setRpmRange1900Mileage(ArithmeticUtils.mileageMToM(var.getRpm1900().getMileage()));
        statisticData.setRpmRange1900Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm1900().getFuel()));
        statisticData.setRpmRange1900Duration(ArithmeticUtils.timeMsToSecond(var.getRpm1900().getDuration()));

        statisticData.setRpmRange2000Mileage(ArithmeticUtils.mileageMToM(var.getRpm2000().getMileage()));
        statisticData.setRpmRange2000Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2000().getFuel()));
        statisticData.setRpmRange2000Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2000().getDuration()));

        statisticData.setRpmRange2100Mileage(ArithmeticUtils.mileageMToM(var.getRpm2100().getMileage()));
        statisticData.setRpmRange2100Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2100().getFuel()));
        statisticData.setRpmRange2100Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2100().getDuration()));

        statisticData.setRpmRange2200Mileage(ArithmeticUtils.mileageMToM(var.getRpm2200().getMileage()));
        statisticData.setRpmRange2200Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2200().getFuel()));
        statisticData.setRpmRange2200Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2200().getDuration()));

        statisticData.setRpmRange2300Mileage(ArithmeticUtils.mileageMToM(var.getRpm2300().getMileage()));
        statisticData.setRpmRange2300Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2300().getFuel()));
        statisticData.setRpmRange2300Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2300().getDuration()));

        statisticData.setRpmRange2400Mileage(ArithmeticUtils.mileageMToM(var.getRpm2400().getMileage()));
        statisticData.setRpmRange2400Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2400().getFuel()));
        statisticData.setRpmRange2400Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2400().getDuration()));

        statisticData.setRpmRange2500Mileage(ArithmeticUtils.mileageMToM(var.getRpm2500().getMileage()));
        statisticData.setRpmRange2500Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2500().getFuel()));
        statisticData.setRpmRange2500Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2500().getDuration()));

        statisticData.setRpmRange2600Mileage(ArithmeticUtils.mileageMToM(var.getRpm2600().getMileage()));
        statisticData.setRpmRange2600Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2600().getFuel()));
        statisticData.setRpmRange2600Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2600().getDuration()));

        statisticData.setRpmRange2700Mileage(ArithmeticUtils.mileageMToM(var.getRpm2700().getMileage()));
        statisticData.setRpmRange2700Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2700().getFuel()));
        statisticData.setRpmRange2700Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2700().getDuration()));

        statisticData.setRpmRange2800Mileage(ArithmeticUtils.mileageMToM(var.getRpm2800().getMileage()));
        statisticData.setRpmRange2800Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2800().getFuel()));
        statisticData.setRpmRange2800Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2800().getDuration()));

        statisticData.setRpmRange2900Mileage(ArithmeticUtils.mileageMToM(var.getRpm2900().getMileage()));
        statisticData.setRpmRange2900Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm2900().getFuel()));
        statisticData.setRpmRange2900Duration(ArithmeticUtils.timeMsToSecond(var.getRpm2900().getDuration()));

        statisticData.setRpmRange3000Mileage(ArithmeticUtils.mileageMToM(var.getRpm3000().getMileage()));
        statisticData.setRpmRange3000Fuel(ArithmeticUtils.fuelMlToMl(var.getRpm3000().getFuel()));
        statisticData.setRpmRange3000Duration(ArithmeticUtils.timeMsToSecond(var.getRpm3000().getDuration()));

        statisticData.setRpmRangeOver3000Mileage(ArithmeticUtils.mileageMToM(var.getRpmOver3000().getMileage()));
        statisticData.setRpmRangeOver3000Fuel(ArithmeticUtils.fuelMlToMl(var.getRpmOver3000().getFuel()));
        statisticData.setRpmRangeOver3000Duration(ArithmeticUtils.timeMsToSecond(var.getRpmOver3000().getDuration()));

        statisticData.setMinRpm(var.getMinRpm());
        statisticData.setMaxRpm(var.getMaxRpm());

        statisticData.setRpmSum(var.getRpmSum());
        statisticData.setRpmCount(var.getRpmCount());

        statisticData.setNoIdleRpmSum(var.getNoIdleRpmSum());
        statisticData.setNoIdleRpmCount(var.getNoIdleRpmCount());
    }
}
